<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
	<head>
		<title>后台管理</title>
		<!-- Meta Tags -->
		<meta charset="UTF-8" />
		<meta name="viewport"	content="user-scalable=no, width=device-width, initial-scale=1.0" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<link rel="shortcut icon" href="__PUBLIC__/assets/images/favicon.ico" />
		<meta http-equiv="X-UA-Compatible" content="IE=8">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!-- Bootstrap Version 3.0-->
		<link rel="stylesheet" href="__PUBLIC__/css/bootstrap.min.css" />
		<link href="__PUBLIC__/css/base.css" type="text/css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/autoreply.css" />
		<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css" />
		<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/font-awesome.min.css" />
		<link rel="stylesheet" href="__PUBLIC__/css/jquery-ui.css" />
		<script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
		<script type="text/javascript" src="__PUBLIC__/js/jquery.cookie.js"></script>
		<script type="text/javascript" src="__PUBLIC__/js/jquery-ui.js"></script>
		<style  type="text/css">
			.blue-bg, .pager li > a.blue-bg{}
			.bg{height: 100%;width: 100%}
		</style>
		<script type="text/javascript">
		var URL = '<?php echo U("Index/verify");?>/';
    	var token="<?php echo ($token); ?>";
    	$(function(){
    		var checked=$.cookie('rememberMe');
    	 	if(checked=='true'){
    	 		document.getElementById('rememberMe').checked=true;
    	 	}else{
    	 		document.getElementById('rememberMe').checked=false;
    	 	}
    	 	$('#username').val($.cookie('username'));
    	 	//var intervalId=window.setInterval(checkIsLogin,5000);
    	});
    	var checking=false;
    	function checkIsLogin(){
    		if(checking){
    			return;
    		}
    		$.ajax({
    			url:"login/checkPadIsClickLogin.json?token=<?php echo ($token); ?>",
    			type:"post",
    			async:true,  
    			dataType:"json",
    			beforeSend : function() {
    				checking = true;
    			},
    			success:function(data){
    				checking=false;
    				if(data.success){
    					window.clearInterval(intervalId);
    					if(data.attribute.isFirstLogin){
    						$('#oldPwd').hide();;
    						$('#firstTip').show();;
    						showSetPwdDialog();
    					}else{
    						showPasswordDialog();
    					}
    				} 
    			}
    		});
    	}
    	
    	function showSetPwdDialog(){
    		$('#setPwdDlg').dialog({
				title:"设置安全密码",
				width:400,
				modal:true,
				resizable:false,
				draggable:false,
				buttons:{'保存密码':function(){
					 savePass();
				},'返回登录':function(){
					$(this).dialog('close');
					showPasswordDialog();
				}}
			});
    	}
    	function savePass(){
    		if($('#confirmPass').val()!=$('#newPass').val()){
    			$('#loginError2 span').html("新密码和确认密码不一致！");
    			$('#loginError2').fadeIn();
    			return;
    		}
			var token="<?php echo ($token); ?>";
    		$.ajax({
    			url:"login/savePassword.json",
    			type:"post",
    			data:{token:token,confirmPass:$('#confirmPass').val(),newPass:$('#newPass').val(),oldPass:$('#oldPass').val()},
    			dataType:"json",
    			success:function(data){
    				if(data.success){
    					location.href='manager/index.json';
    				}else{
    					$('#loginError2 span').html(data.message);
    					$("#loginError2").fadeIn();
    				}
    			}
    		});
    	}
    	function showPasswordDialog(){
    		$('#loginDlg').dialog({
				title:"身份认证",
				width:400,
				modal:true,
				resizable:false,
				draggable:false,
				buttons:{'确认登录':function(){
					$.ajax({
		    			url:"login/checkPassword.json?token={$token}",
		    			type:"post",
		    			data:{pwd:$('#sec_pwd').val()},
		    			dataType:"json",
		    			success:function(data){
		    				if(data.success){
		    					 location.href='manager/index.json';
		    				}else{
		    					$('#loginError1 span').html(data.message);
		    					$('#loginError1').fadeIn();
		    				}
		    			}
		    		});

				},'修改密码':function(){
					$(this).dialog('close');
					showSetPwdDialog();
				}}
			});
			$('#loginDlg').css('width','100%');
    	}
    	 
    	 function login(){
    	 	var rememberMe=document.getElementById('rememberMe').checked;
    	 	if(rememberMe){
    	 		$.cookie('username',$('#username').val());
    	 		$.cookie('rememberMe',true)
    	 	}else{
    	 		$.cookie('username','');
    	 		$.cookie('rememberMe',false)
    	 	}
    	 	$.ajax({
    	 		url:"<?php echo U('Index/commonLogin');?>" ,
    	 		type:"post",
    	 		dataType:"json",
    	 		data:{'username':$('#username').val(),'pwd':$('#pwd').val(),'code':$('#code').val()},
    	 		success:function(data){
    	 			if(data.success){
    	 				 location.href="<?php echo U('Client/manage');?>";
    	 			}else{
    	 				alert(data.message);
    	 			}
    	 		}
    	 	});
    	 }
    	 function ok(e){
    		 var event = e ?e: window.event;
    		 if(event.keyCode==13){
    			 login();
    		 }
    	 }
		 function changecode(obj){
		   $(obj).attr("src",URL+Math.random());
		}
    </script>
	</head>
	<body class="blue-bg mybg"   >
	<div class='bg' align="center">
		
		<div class="signin panel" style="margin-top: 50px">
			<div class="signin-body">
				<h3 class="panel-heading">
					<i class='fa fa-key'></i>登录系统
				</h3>
				<div>
					<table>
					<tr>
						<td valign="top">
							<!--<img src="<?php echo U('Index/qrcode');?>/token/<?php echo ($token); ?>" onclick="$('#zoomCode').fadeIn()" style="border:1px solid #fff; width: 120px; height: 120px; background: #333;margin-right: 10px">
							-->
							<img src="__PUBLIC__/images/ddww.jpg" onclick="$('#zoomCode').fadeIn()" style="border:1px solid #fff; width: 120px; height: 120px; background: #333;margin-right: 10px">
							
							<div align='center' onclick="$('#zoomCode').fadeIn()">点击放大</div>
						</td>
						<td valign="top">
							<form id="basic-validation">
								<div class="form-group">
									<input type="text" class="form-control" placeholder="账号"
										 id="username">
								</div>
								<div class="form-group">
									<input type="password" class="form-control"
										placeholder="密码"  id="pwd">
								</div>
								<div class="form-group">
								<input id='code' class='form-control' size="4" onkeypress="ok(event)" style="width: 100px;display: inline-block"/>
								<img  src="<?php echo U('Index/verify');?>"  onclick="changecode(this)" style="height: 30px;margin-left: 5px"/>
								</div>
								<div class="form-group clearfix">
									<label class="btn btn-med blue-bg " for="rememberMe">
										<input type="checkbox"  id='rememberMe' style="margin: 0px">
										记住我
									</label>
									<a type="button" class="btn btn-med blue-bg  " style="width: 100px" onclick="login()" >登录</a>
								</div>

							</form>
						</td>
					</tr>
				</table>
				</div>
				<hr>
			</div>
		</div>
		<!-- dialog -->
		<div id='loginDlg' style="display: none;">
				<div class='alert alert-warning' id='loginError1' style="display: none">
					<img src='__PUBLIC__/img/msg_state_fail_resend.png' height="22px" />
					<span>密码错误，请确认您的安全密码！</span>
				</div>
				<div id='line1'>
					安全密码：
					<input id='sec_pwd' type="password" style="height: 26px;">
				</div>
			</div>
			<div id='setPwdDlg' style="display: none">
				<div id='line2' align="left">
					<div class='errorMsg' id='loginError2'>
						<img src='__PUBLIC__/img/msg_state_fail_resend.png' height="22px" />
						<span></span>
					</div>
					<div id='firstTip'
						style="font-size: 12px; display: none; color: rgb(0, 162, 232)">
						您好，您是第一次登录系统，请设置安全密码
					</div>
					<div id='oldPwd'>
						旧安全码：
						<input type="password" style="height: 26px;" id='oldPass' />
					</div>
					<div>
						新安全码：
						<input type="password" style="height: 26px;" id='newPass' />
					</div>
					<div>
						确认密码：
						<input type="password" style="height: 26px;" id='confirmPass' />
					</div>
					<hr
						style="border: none; border-top: 1px solid #ccc; border-bottom: 1px solid #fff;">
					<div style="font-size: 12px">注：设置您的安全密码，以防别人盗用您的平板，使用公众平台功能</div>
				</div>
			</div>
			</div>
			<div style="position: fixed;width: 100%;height: 100%;left:0px;top: 0px;background: rgba(0,0,0,0.2);text-align: center;display: none" id='zoomCode'>
				<img alt="" src="__PUBLIC__/img/close.png" style="position:relative ;top: -100px;height: 30px;width: 30px;right: -20px;" onclick="$('#zoomCode').fadeOut()">
				<img src="__PUBLIC__/images/ddww.jpg"	style="border:1px solid #fff;  background: #333;margin-top: 100px">
			</div>
	</body>
</html>